package com.example.park2212.repair

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.lib_base.entity.RepairBean
import com.example.lib_base.entity.RepairBeanItem
import com.example.lib_base.mvvm.BaseActivity
import com.example.park2212.R
import com.example.park2212.databinding.ActivityRepairDetailBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/repair/RepairDetailActivity")
class RepairDetailActivity : BaseActivity<ActivityRepairDetailBinding,RepairViewModel>() {
    @Autowired
    lateinit var rid:String
    lateinit var bean: RepairBeanItem
    override fun initView() {
        binding.headRepDetail.headerAdd.setOnClickListener {

        }

        ARouter.getInstance().inject(this)
        viewModel.getPairById(rid.toInt())

        binding.repDetailOk.setOnClickListener {
            approve("处理中")
        }
        binding.repDetailRefause.setOnClickListener {
            approve(("已完成"))
        }

    }

    override fun initData() {
        viewModel.getPairByIdSuccess.observe(this){
            Log.i("===",it.toString())
            binding.bean = it
            bean = it

//           if(it.processingStatus!="已完成"){
//               binding.repDetailGroup.visibility=View.VISIBLE
//           }

            if(it.processingStatus=="处理中"){
                binding.repDetailProCircle2.setBackgroundResource(R.drawable.shape_solid_darkgreen)
                binding.repDetailGroup.visibility= View.VISIBLE
            }else if(it.processingStatus=="已完成"){
                binding.repDetailProCircle2.setBackgroundResource(R.drawable.shape_solid_darkgreen)
                binding.repDetailProCircle3.setBackgroundResource(R.drawable.shape_solid_darkgreen)
            }else{
                binding.repDetailGroup.visibility=View.VISIBLE
            }

        }


        viewModel.updatePairSuccess.observe(this){
            ToastUtils.showLong("操作完成")
            finish()
        }


    }

    fun approve(status:String){
        bean.processingStatus = status
        viewModel.updatePair(rid.toInt(),bean)
    }

}